var saveOrUpdate;
var reset;
var reload;
var issueParameters;
require(['layout','validator','date','select2'], function () {
	$('#saas').initForm();
	//添加或更新
	saveOrUpdate = function (fn){
		if($('#vrsnId').val()){
			$.messager.confirm("是否更新", "是否更新该模板信息？", function(r) {
				if (r) {
					if($.validator($('#saas'))){
						var $data = $('#saas').serializeArray();
						$data.push({name:'vrsnType',value:'VERS0007'});
						$data.push({name:'appUpgrade',value:'AIRC0003'});
						$.ajaxExt({
							url : "/airConditioner/updateAirTemplate.htm",
							data : $data
						}).done(function(result){
							fn();
						});
					}
				}
			});
		}
		else{
			if($.validator($('#saas'))){
				var $data = $('#saas').serializeArray();
				$data.push({name:'vrsnType',value:'VERS0007'});
				$data.push({name:'appUpgrade',value:'AIRC0003'});
				$.ajaxExt({
					url : "/airConditioner/addAirTemplate.htm",
					data : $data
				}).done(function(result){
					fn();
				});
			}
		}
	}
	
	//重置
	reset=function(reset){
		if($('#vrsnId').val() && reset ==null){
			reload($('#vrsnId').val());
		}
		else{
			$('#saas').reset();
		}
	}
	
	//重新加载
	reload=function(vrsnId){
		$.ajaxExt({
			url : "/airConditioner/getAirTemplateById.htm",
			data : [{name:'vrsnId',value:vrsnId}]
		}).done(function(data){
			var airData=data;
			$('#saas').setValues(airData);
		});
	}

	issueParameters=function(fn){
		if($.validator($('#saas'))){
			var $data = $('#saas').serializeArray();
			var type = commonFun.getLeftTreeCurrentTreeType();
			var orgIds = commonFun.getLeftTreeCheckedNodes(type);
			$data.push({name:'orgIds',value:orgIds});
			$data.push({name:'vrsnType',value:'VERS0007'});
			$data.push({name:'appUpgrade',value:'AIRC0003'});
			$.ajaxExt({
				url : "/airConditioner/templateAirConditioIssued.htm",
				data : $data
			}).done(function(result){
				fn();
			});
		}
	}
});